Repository navigation
fix: verify the card-token webhooks, and surface the card they carry - #2
Open
MHJaafar9869 wants to merge 1 commit into
Open
MHJaafar9869 wants to merge 1 commit into
MHJaafar9869 wants to merge 1 commit into
Conversation
`card_token.created` and `card_token.failed` were unverifiable. The server signs by opt-out — PaymentIntegrationWebhookJob copies the payload and unsets a fixed exclusion list before hashing — so the tokenisation block it writes for these two events is signed in full: `tokenization_id`, `external_reference`, and, once the card is vaulted, `card_token`, `card_brand`, `card_last4`, `card_exp_month` and `card_exp_year`. This SDK signed none of them, so every card-token webhook failed verification. Both events are on by default for every integration, because a hosted tokenisation has no other way to deliver its token, so this reached anyone saving cards. The signed values are now rebuilt the way the server assembles them, a block at a time: a block is gated on its own leading field, and a key keeps the position it was first written at. That ordering is the whole of it — the signature is a separator-less concatenation, and on an event with no mandate `external_reference` is signed after `tokenization_id`, not at the slot it holds on a subscription event. The card is also readable off WebhookEvent now. The record keeps a constructor with its previous shape so positional construction still compiles. Two golden vectors cover the vaulted card and a failed tokenisation that carries no card at all; they are the same vectors the other SDKs verify against.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
card_token.createdandcard_token.failedcould not be verified by this SDK, and the card they carry was not readable off the event.Why
The server signs by opt-out:
PaymentIntegrationWebhookJobcopies the payload andunset()s a fixed exclusion list before hashing. The tokenisation block it writes for these two events is therefore signed in full —tokenization_id,external_reference, and, once the card is vaulted,card_token,card_brand,card_last4,card_exp_month,card_exp_year.This SDK signed none of them, so
verify()rejected every card-token webhook. Both events are on by default for every integration — a hosted tokenisation has no other way to deliver its token — so this affected anyone saving cards.How
external_referenceis signed aftertokenization_id, not at the slot it holds on a subscription event.CARD_TOKEN_CREATEDandCARD_TOKEN_FAILEDadded toWebhookEventType.tokenizationId(),cardToken(),cardBrand(),cardLast4(),cardExpMonth(),cardExpYear()on theWebhookEventrecord, which keeps a constructor with its previous shape so positional construction still compiles.Tests
Two golden vectors — a vaulted card and a failed tokenisation carrying no card — added to
golden-signatures.json, the same file the js, php, python and dotnet SDKs verify against.GoldenSignatureTestpicks them up automatically;WebhookTestcovers the card accessors, acard_token.failedevent with no card, and a tamperedcard_last4. The test helper's signing now mirrors the same block ordering.There is no Maven on the machine this was written on, so
WebhookTestandGoldenSignatureTestwere compiled and run directly against JDK 17 with the junit console launcher: 13 tests, all passing. CI runs the full build.Version 0.2.0 → 0.3.0 across the parent and both modules.